package com.iplant.basic.serviceImpl;

import com.iplant.base.po.excel.ExcelData;
import com.iplant.base.po.excel.ExcelLineData;
import com.iplant.base.po.excel.ExcelSheetData;
import com.iplant.base.utils.general.StringUtils;
import com.iplant.base.utils.sql.orm.ORMUtils;
import com.iplant.base.utils.sql.orm.PoService;
import com.iplant.basic.service.MSSService;
import com.iplant.basic.service.po.mss.*;
import com.iplant.basic.serviceImpl.dao.mss.*;
import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.basic.service.po.bms.BMSEmployee;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class MSSServiceImpl implements MSSService {

    //region 构造函数
    public MSSServiceImpl() {
        // TODO Auto-generated constructor stub
    }
    //endregion

    //region logger
    private static final Logger logger = LoggerFactory.getLogger(MSSServiceImpl.class);
    //endregion

    //region 单实例
    private static MSSService Instance = null;

    public static MSSService getInstance() {
        if (Instance == null) {
            Instance = new MSSServiceImpl();
        }

        return Instance;
    }
    //endregion

    //region POService
    PoService<MSSMaterial> mMSSMaterialService = ORMUtils.GetPoService(MSSMaterial.class);
    PoService<MSSMaterialGroup> mMSSMaterialGroupService = ORMUtils.GetPoService(MSSMaterialGroup.class);
    PoService<MSSMaterialType> mMSSMaterialTypeService = ORMUtils.GetPoService(MSSMaterialType.class);
    PoService<MSSUnit> mMSSUnitService = ORMUtils.GetPoService(MSSUnit.class);
    //endregion

    //region 老接口

    @Override
    public ServiceResult<Integer> MSS_UpdateUnit(BMSEmployee wLoginUser, MSSUnit wUnit) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitDAO.getInstance().MSS_UpdateUnit(wLoginUser, wUnit, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteUnit(BMSEmployee wLoginUser, MSSUnit wUnit) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitDAO.getInstance().DeletePO(wLoginUser, wUnit, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveUnit(BMSEmployee wLoginUser, MSSUnit wUnit, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitDAO.getInstance().MSS_ActiveUnit(wLoginUser, wUnit, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSUnit> MSS_QueryUnit(BMSEmployee wLoginUser, int wID, String wCode) {

        ServiceResult<MSSUnit> wResult = new ServiceResult<MSSUnit>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSUnitDAO.getInstance().MSS_QueryUnit(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSUnit>> MSS_QueryUnitList(
            BMSEmployee wLoginUser, int wGroupID, String wGroupFullName, String wName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSUnit>> wResult = new ServiceResult<List<MSSUnit>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSUnitDAO.getInstance().MSS_QueryUnitList(wLoginUser, wGroupID, wGroupFullName, wName,
                    wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    // 单位组

    @Override
    public ServiceResult<Integer> MSS_UpdateUnitGroup(BMSEmployee wLoginUser, MSSUnitGroup wUnitGroup) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitGroupDAO.getInstance().MSS_UpdateUnitGroup(wLoginUser, wUnitGroup, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteUnitGroup(BMSEmployee wLoginUser, MSSUnitGroup wUnitGroup) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitGroupDAO.getInstance().DeletePO(wLoginUser, wUnitGroup, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveUnitGroup(BMSEmployee wLoginUser, MSSUnitGroup wUnitGroup, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSUnitGroupDAO.getInstance().MSS_ActiveUnitGroup(wLoginUser, wUnitGroup, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSUnitGroup> MSS_QueryUnitGroup(BMSEmployee wLoginUser, int wID, String wCode) {

        ServiceResult<MSSUnitGroup> wResult = new ServiceResult<MSSUnitGroup>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSUnitGroupDAO.getInstance().MSS_QueryUnitGroup(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSUnitGroup>> MSS_QueryUnitGroupList(
            BMSEmployee wLoginUser, int wParentGroupID, String wGroupFullName, String wName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSUnitGroup>> wResult = new ServiceResult<List<MSSUnitGroup>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSUnitGroupDAO.getInstance().MSS_QueryUnitGroupList(wLoginUser, wName, wParentGroupID,
                    wGroupFullName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> MSS_UpdateMaterialType(BMSEmployee wLoginUser, MSSMaterialType wMaterialType) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialTypeDAO.getInstance().MSS_UpdateMaterialType(wLoginUser, wMaterialType, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteMaterialType(BMSEmployee wLoginUser, MSSMaterialType wMaterialType) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialTypeDAO.getInstance().DeletePO(wLoginUser, wMaterialType, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveMaterialType(
            BMSEmployee wLoginUser, MSSMaterialType wMaterialType, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialTypeDAO.getInstance().MSS_ActiveMaterialType(wLoginUser, wMaterialType, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSMaterialType> MSS_QueryMaterialType(BMSEmployee wLoginUser, int wID, String wCode) {

        ServiceResult<MSSMaterialType> wResult = new ServiceResult<MSSMaterialType>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialTypeDAO.getInstance().MSS_QueryMaterialType(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSMaterialType>> MSS_QueryMaterialTypeList(
            BMSEmployee wLoginUser, String wName, int wActive, Pagination wPagination) {
        ServiceResult<List<MSSMaterialType>> wResult = new ServiceResult<List<MSSMaterialType>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialTypeDAO.getInstance().MSS_QueryMaterialTypeList(wLoginUser, wName, wActive,
                    wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_UpdateMaterialGroup(BMSEmployee wLoginUser, MSSMaterialGroup wMaterialGroup) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialGroupDAO.getInstance().MSS_UpdateMaterialGroup(wLoginUser, wMaterialGroup, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteMaterialGroup(BMSEmployee wLoginUser, MSSMaterialGroup wMaterialGroup) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialGroupDAO.getInstance().DeletePO(wLoginUser, wMaterialGroup, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveMaterialGroup(
            BMSEmployee wLoginUser, MSSMaterialGroup wMaterialGroup, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialGroupDAO.getInstance().MSS_ActiveMaterialGroup(wLoginUser, wMaterialGroup, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSMaterialGroup> MSS_QueryMaterialGroup(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSMaterialGroup> wResult = new ServiceResult<MSSMaterialGroup>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialGroupDAO.getInstance().MSS_QueryMaterialGroup(wLoginUser, wID, wCode,
                    wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSMaterialGroup>> MSS_QueryMaterialGroupList(
            BMSEmployee wLoginUser, String wName, int wParentGroupID, String wGroupFullName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<MSSMaterialGroup>> wResult = new ServiceResult<List<MSSMaterialGroup>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialGroupDAO.getInstance().MSS_QueryMaterialGroupList(wLoginUser, wName,
                    wParentGroupID, wGroupFullName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_UpdateMaterial(BMSEmployee wLoginUser, MSSMaterial wMaterial) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialDAO.getInstance().UpdatePo(wLoginUser, wMaterial, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_UpdateMaterialList(BMSEmployee wLoginUser, List<MSSMaterial> wMaterialList) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialDAO.getInstance().UpdatePoList(wLoginUser, wMaterialList, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_DeleteMaterial(BMSEmployee wLoginUser, MSSMaterial wMaterial) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialDAO.getInstance().DeletePO(wLoginUser, wMaterial, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> MSS_ActiveMaterial(BMSEmployee wLoginUser, MSSMaterial wMaterial, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            MSSMaterialDAO.getInstance().ActivePO(wLoginUser, wMaterial, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<MSSMaterial>> MSS_QueryMaterialList(
            BMSEmployee wLoginUser, String wMaterialNoLike,
            String wMaterialNameLike, int wMaterialTypeID, int wMaterialGroupID, int wTypeID,
            String wMaterialFullGroup, String wMaterialMode, String wDrawingNoLike, int wRecoil,
            int wOutsourced, int wActive, Pagination wPagination) {
        ServiceResult<List<MSSMaterial>> wResult = new ServiceResult<List<MSSMaterial>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialDAO.getInstance().MSS_QueryMaterialList(wLoginUser,
                    wMaterialNoLike, wMaterialNameLike, wMaterialTypeID, wMaterialGroupID, wTypeID,
                    wMaterialFullGroup, wMaterialMode, wDrawingNoLike, wRecoil, wOutsourced, wActive, wPagination,
                    wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<MSSMaterial> MSS_QueryMaterial(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<MSSMaterial> wResult = new ServiceResult<MSSMaterial>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = MSSMaterialDAO.getInstance().SelectPO(wLoginUser, wID, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //endregion

    @Override
    public ServiceResult<Integer> MSS_ImportMaterial(BMSEmployee wLoginUser, ExcelData wExcelData) {
        ServiceResult<Integer> wResult = new ServiceResult<>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<>(0);

            if (wExcelData == null || wExcelData.sheetData == null || wExcelData.sheetData.size() <= 0) {
                wResult.FaultCode += "导入失败：Excel格式错误!!!";
                return wResult;
            }

            ExcelSheetData wExcelSheetData = wExcelData.sheetData.get(0);
            if (wExcelSheetData.lineData == null || wExcelSheetData.lineData.size() <= 1) {
                wResult.FaultCode += "导入失败：Excel无内容!!!";
                return wResult;
            }

            //①物料分组
            Map<String, Object> wParams = new HashMap<String, Object>();
            List<MSSMaterialGroup> wMSSMaterialGroupList = mMSSMaterialGroupService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSMaterialGroupList == null || wMSSMaterialGroupList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到物料分组信息!!!";
                return wResult;
            }
            Map<String, Integer> wNameIDGroupMap =
                    wMSSMaterialGroupList.stream().collect(Collectors.toMap(MSSMaterialGroup::getName
                            , MSSMaterialGroup::getID));
            //②产品类型
            List<MSSMaterialType> wMSSMaterialTypeList = mMSSMaterialTypeService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSMaterialTypeList == null || wMSSMaterialTypeList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到物料类型信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDTypeMap =
                    wMSSMaterialTypeList.stream().collect(Collectors.toMap(MSSMaterialType::getName
                            , MSSMaterialType::getID));

            //③计量单位
            List<MSSUnit> wMSSUnitList = mMSSUnitService.SelectPOList(wLoginUser, wParams,
                    Pagination.getNewMaxSize(),
                    wErrorCode);
            if (wMSSUnitList == null || wMSSUnitList.size() <= 0) {
                wResult.FaultCode += "导入失败：未获取到物料单位信息!!!";
                return wResult;
            }

            Map<String, Integer> wNameIDUnitMap =
                    wMSSUnitList.stream().collect(Collectors.toMap(MSSUnit::getCode
                            , MSSUnit::getID));

            List<MSSMaterial> wMSSMaterialList = new ArrayList<>();
            MSSMaterial wMSSMaterial;
            ExcelLineData wExcelLineData;
            int wIndex;
            for (int i = 0; i < wExcelSheetData.lineData.size(); i++) {
                if (i == 0) {
                    continue;
                }

                wExcelLineData = wExcelSheetData.lineData.get(i);
                wIndex = 0;

                //物料编码
                String wCol1 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol1)) {
                    continue;
                }
                //物料名称
                String wCol2 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol2)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，物料名称不能为空!!!", i + 1);
                    return wResult;
                }
                //规格型号
                String wCol3 = wExcelLineData.colData.get(wIndex++);
                //品牌/制造商
                String wCol4 = wExcelLineData.colData.get(wIndex++);
                //计量单位
                String wCol5 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol5)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，计量单位不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDUnitMap.containsKey(wCol5)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，计量单位信息【{1}】不存在!!!", i + 1, wCol5);
                    return wResult;
                }
                //单价
                String wCol6 = wExcelLineData.colData.get(wIndex++);
                //供应商
                String wCol7 = wExcelLineData.colData.get(wIndex++);
                //存放位置
                String wCol8 = wExcelLineData.colData.get(wIndex++);
                //归属产品型号（编码）
                String wCol9 = wExcelLineData.colData.get(wIndex++);
                //物料分组
                String wCol10 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol10)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，物料分组不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDGroupMap.containsKey(wCol10)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，物料分组信息【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //物料类型
                String wCol11 = wExcelLineData.colData.get(wIndex++);
                if (StringUtils.isEmpty(wCol11)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，物料类型不能为空!!!", i + 1);
                    return wResult;
                }
                if (!wNameIDTypeMap.containsKey(wCol11)) {
                    wResult.FaultCode += StringUtils.Format("导入失败：第【{0}】行数据有误，物料类型信息【{1}】不存在!!!", i + 1, wCol3);
                    return wResult;
                }
                //描述信息
                String wCol12 = wExcelLineData.colData.get(wIndex++);

                //添加到结果集，后续批量保存
                wMSSMaterial = new MSSMaterial();
                wMSSMaterial.Code = wCol1;
                wMSSMaterial.Name = wCol2;
                wMSSMaterial.MaterialName = wCol2;
                wMSSMaterial.Groes = wCol3;
                wMSSMaterial.Manufacturer = wCol4;
                wMSSMaterial.CYUnitID = wNameIDUnitMap.get(wCol5);
                wMSSMaterial.UnitPrice = StringUtils.parseFloat(wCol6);
                wMSSMaterial.Supplier = wCol7;
                wMSSMaterial.Position = wCol8;
                wMSSMaterial.ProductNo = wCol9;
                wMSSMaterial.MaterialGroupID = wNameIDGroupMap.get(wCol10);
                wMSSMaterial.MaterialTypeID = wNameIDTypeMap.get(wCol11);
                wMSSMaterial.Description = wCol12;
                wMSSMaterialList.add(wMSSMaterial);
            }
            if (wMSSMaterialList.size() > 0) {
                mMSSMaterialService.UpdatePoList(wLoginUser, wMSSMaterialList, wErrorCode);
            }

            wResult.setFaultCode(ExceptionTypes.getEnumType(wErrorCode.Result).getLabel());
        } catch (Exception e) {
            wResult.FaultCode += e.toString();
            logger.error("MSS_ImportMaterial", e);
        }
        return wResult;
    }
}
